<?php
/**
 * @author xianglvs
 *
 */
abstract class Validate{
    private $result = false;
    private $error = '参数验证失败';
    private $success = '参数验证成功';
    protected $param = array();
    
    public function __construct($condition=array()){
    	$this->handle($condition);
    }
    
    public function getParam(){
    	return $this->param;
    }
    
    public function setParam($condition){
    	$this->param = $condition;
    }
    /**
     * 验证结果
     * @return bool
     * true 验证通过
     * false 验证失败
     */
    public function getResult(){
    	return $this->result;
    }
    /**
     * 验证失败后的信息不设默认提示为:参数验证失败
     * @return String
     */
    public function getError(){
    	return $this->error;
    }
    /**
     * 验证成功后的信息不设默认提示为:参数验证成功
     * @return String
     */
    public function getSuccess(){
    	return $this->success;
    }
    /**
     * 执行验证操作
     * @return array 验证方法valid执行后的结果
     */
    public function handle($condition){
    	$this->param = $condition;
    	$res = $this->valid();
    	if($res['result'] == 'success'){
    		$this->result = true;
    		if(!empty($res['success'])){
    			$this->success = $res['success'];
    		}
    	}else{
    		$this->result = false;
    		if(!empty($res['error'])){
    			$this->error = $res['error'];
    		}
    	}
    	return $res;
    }
	/**
	 * 校验方法
	 * return array
	 * array:
	 * key:type
	 * value : success/failed
	 * key:error
	 * value : 错误描述
	 * key:success
	 * value : 成功描述
	 */
    protected abstract function valid();
}
?>